package com.zmh.thread.muilt_thread_print;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author zmh
 * @create 2019-07-20 11:34
 **/
public class CyclicBarrierTest {

    static CyclicBarrier cyclicBarrier = new CyclicBarrier(9);

    static class P extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
            try {
                cyclicBarrier.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (BrokenBarrierException e) {
                e.printStackTrace();
            }
        }
    }



    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        for (int i = 0; i <9999; i++) {
            new P().start();
        }
        cyclicBarrier.await();
        System.out.println("main haha");
    }

}
